Improve api for Caveat Enforcer actions and Client#50
Merged
hanzel98 merged 19 commits intoAug 8, 2025
Conversation
- Add new action functions that accept entire delegation instead of delegation hash and args - Add findMatchingCaveat utility function to extract caveat data from delegation - Add NoMatchingCaveatError and MultipleMatchingCaveatsError for error handling - Add comprehensive test coverage for new functionality - Maintain backward compatibility with existing action functions
|
Cursor Agent can help with this pull request. Just |
jeffsmale90
marked this pull request as ready for review
August 7, 2025 00:04
jeffsmale90
commented
Aug 7, 2025
jeffsmale90
commented
Aug 7, 2025
jeffsmale90
force-pushed
the
cursor/accept-delegation-object-and-move-client-export-9bcd
branch
from
August 7, 2025 01:38
98eab59 to
5c2e0a5
Compare
…hDelegation directly. Use type assertion when destructuring foundCaveats.
jeffsmale90
force-pushed
the
cursor/accept-delegation-object-and-move-client-export-9bcd
branch
2 times, most recently
from
August 7, 2025 02:08
5592f5d to
c4fa6d4
Compare
jeffsmale90
force-pushed
the
cursor/accept-delegation-object-and-move-client-export-9bcd
branch
from
August 7, 2025 02:38
c4fa6d4 to
89628de
Compare
hanzel98
reviewed
Aug 7, 2025
hanzel98
reviewed
Aug 7, 2025
hanzel98
reviewed
Aug 7, 2025
hanzel98
reviewed
Aug 7, 2025
…tion messages when caveats are not found, or duplicates are found.
jeffsmale90
force-pushed
the
cursor/accept-delegation-object-and-move-client-export-9bcd
branch
from
August 8, 2025 00:33
0b1a78e to
0b03514
Compare
hanzel98
reviewed
Aug 8, 2025
hanzel98
approved these changes
Aug 8, 2025
hanzel98
deleted the
cursor/accept-delegation-object-and-move-client-export-9bcd
branch
August 8, 2025 02:19
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📝 Description
This PR refactors the caveat enforcer actions and client within the
@metamask/delegation-toolkitpackage to simplify their API and improve developer experience.Note: This PR was authored with Cursor Agent.
🔄 What Changed?
getMultiTokenPeriodEnforcerAvailableAmount) now exclusively accept a single parameter:{ delegation: Delegation }.delegationManagerandenforcerAddressare no longer accepted as explicit parameters; they are always derived from theenvironmentobject. This simplifies the interface, and allows for this functionality to be added in the future.createCaveatEnforcerClientandCaveatEnforcerClientare now exported to the main API export at@metamask/delegation-toolkitwhile the individual actions and the actions factory are exported at@metamask/delegation-toolkit/actions🚀 Why?
Delegationobject.CaveatEnforcerClientto the main package export makes it more discoverable and directly accessible.Errorobjects aligns with common JavaScript error handling patterns.🧪 How to Test?
createCaveatEnforcerClientfrom@metamask/delegation-toolkitand verify it can be instantiated.client.getMultiTokenPeriodEnforcerAvailableAmount) passing only a{ delegation: Delegation }object and confirm correct results.Errorwith a descriptive message is thrown.{ delegation: Delegation }object. The previous parameters (delegationHash,terms,args,delegationManager,enforcerAddress) are no longer accepted.This is only a breaking change in development, as these interfaces have not been released.
📋 Checklist
🔗 Related Issues
Closes #
Related to #
📚 Additional Notes
This PR is the result of several iterations to refine the API based on feedback, leading to a much cleaner and more intuitive interface for interacting with caveat enforcer contracts.